
/*
 * This is the extension activity for a 'SilentAction' activity associated
 * with service '{http://www.pi4soa.org/AuctionHouseSeller}AuctionHouse'
 * and behavior 'main'. The name of the
 * activity is 'StoreAuctionItem'.
 */
package org.pi4soa.auctionhouseseller.auctionhouse.main;

import java.util.Set;

import org.pi4soa.service.DeferProcessingException;
import org.pi4soa.service.ServiceException;
import org.pi4soa.service.extensions.DefaultActivityExtension;
import org.pi4soa.service.extensions.ExtensionContext;
import org.pi4soa.service.extensions.SilentActivityExtension;

import dk.itu.amds.auctionhouse.data.AuctionHouseDB;
import dk.itu.amds.auctionhouse.domain.AuctionHouse;
import dk.itu.amds.auctionhouse.domain.AuctionItem;

/**
 * This class has been autogenerated to implement the custom
 * activity within a service endpoint description.
 */
public class StoreAuctionItemActivity extends DefaultActivityExtension
					implements SilentActivityExtension {

	/**
	 * The constructor for the activity extension.
	 */
	public StoreAuctionItemActivity() {
	}
	
	/**
	 * This method enables an activity extension to
	 * perform activities that are not observable.
	 * 
	 * @param context The context
	 * @exception DeferProcessingException Suspend processing
	 * @exception ServiceException Failed to perform silent action
	 */
	public void process(ExtensionContext context)
				throws DeferProcessingException, ServiceException {


		AuctionHouseDB db = new AuctionHouseDB();
		
		AuctionHouse auctionHouse = db.getAuctionHouse();
		
		
		
		int userId = Integer.parseInt(context.getVariable("userId").toString());
		String itemName = context.getVariable("itemName").toString();
		String itemDescription = context.getVariable("itemDescription").toString();
		float startPrice = Float.parseFloat(context.getVariable("startPrice").toString());
		float maxPrice = Float.parseFloat(context.getVariable("maxPrice").toString());
		int sellerBrokerAccountId = Integer.parseInt(context.getVariable("sellerBrokerAccountId").toString());
		
		AuctionItem auctionItem = new AuctionItem(itemName, itemDescription, startPrice, maxPrice, userId, sellerBrokerAccountId);
		
		auctionHouse.addAuctionItem(auctionItem);
		
		db.store();
		
		System.err.println("StoreAuctionItemActivity: Auction item stored...");
		// TODO: Add code to perform tasks relevant to
		// the Silent Action.
		
	}
}	